import HDataTable from "@/components/ant-ext-table/HDataTable";
import HTag from "@/components/ant-ext/HTag";
import {ContractStat, ContractType, PaymentStat} from "@/const/const";
import {Form} from "antd";
import React from "react";
import {Dispatch} from "redux";
import {HTableProps} from "@/components/ant-ext-table/HTable";
import {useDispatch} from "react-redux";
import EntityContract from "@/api/entity-contract";
import {DeleteOutlined} from "@ant-design/icons";
import {HDataTableSlice} from "@/components/ant-ext-table/redux/dataTableSlice";

function getColumns(dispatch: Dispatch): HTableProps<any>["columns"] {
    return [
        {
            title: "合同订单号",
            dataIndex: 'contractNo',
            width: '200px',
            fixed: 'left',
        }, {
            title: "合同类型",
            dataIndex: 'type',
            width: '80px',
            render: (value: any) => <HTag value={value} mapping={ContractType.tag}/>
        }, {
            title: "合同状态",
            dataIndex: 'stat',
            width: '80px',
            render: (value: any) => <HTag value={value} mapping={ContractStat.tag}/>
        }, {
            title: "债权人",
            dataIndex: 'hoName',
        }, {
            title: "债务人",
            dataIndex: 'coName',
        }, {
            title: "债务人联系方式",
            dataIndex: 'coMobile',
        }, {
            title: "支付金额",
            dataIndex: 'amount',
        }, {
            title: "收费金额",
            dataIndex: 'chargeAmount',
        }, {
            title: "备注",
            dataIndex: 'remark',
        }, {
            title: "支付状态",
            width: '80px',
            dataIndex: 'payment',
            render: (value: any) => <HTag value={value} mapping={PaymentStat.tag}/>
        }, {
            title: "创建时间",
            width: '150px',
            dataIndex: 'createTime',
        }, {
            title: "同意时间",
            width: '150px',
            dataIndex: 'agreeTime',
        }, {
            title: "微信支付ID",
            dataIndex: 'paymentOperationId',
        }
    ]
}

export default function Trade() {
    const [form] = Form.useForm()
    const dispatch = useDispatch()

    return <>
        <HDataTable
            option={[
                {
                    key: EntityContract.DEL,
                    title: "删除",
                    mode: "multi",
                    icon: <DeleteOutlined style={{color: "red"}}/>,
                    confirm: "是否要删除所选数据",
                    action: (data) => {
                        EntityContract.delete({
                            body: {code: data.selectRowKeys},
                            success: () => dispatch(HDataTableSlice.actions.setQueryParams({}))
                        })
                    }
                },
            ]}
            queryForm={{
                form: form,
                item: [
                    {name: "hoName", label: "持有人名称"},
                    {name: "coName", label: "债务人名称"},
                    {name: "stat", label: "订单状态", type: "select", dataSource: ContractStat.select, width: "150px"},
                    {name: "payment", label: "支付状态", type: "radio", dataSource: PaymentStat.select, width: "150px"},
                ]
            }}
            columns={getColumns(dispatch)} selectMethod={EntityContract.selectTablePage}
            rowKey={EntityContract.RowKey}
        />
    </>
}